<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="参保城市" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入参保城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hrmanagement:city:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hrmanagement:city:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hrmanagement:city:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hrmanagement:city:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="参保城市" align="center" prop="name" />
      <el-table-column label="社保缴纳基数" align="center" >

        <el-table-column label="上限" align="center" prop="socUpperLimit" />
      <el-table-column label="下限" align="center" prop="socLowerLimit" />



      </el-table-column>
      <el-table-column label="公积金缴纳比例" align="center" >


        <el-table-column label="上限" align="center" prop="houUpperLimit" />
      <el-table-column label="下限" align="center" prop="houLowerLimit" />


</el-table-column>


<el-table-column label="养老保险缴纳比例" align="center" >
  <el-table-column label="个人" align="center" prop="perPensionRate" />
      <el-table-column label="企业" align="center" prop="comPensionRate" />




</el-table-column>


<el-table-column label="医疗保险缴纳比例" align="center" >

  <el-table-column label="个人" align="center" prop="perMedicalRate" />
      <el-table-column label="企业" align="center" prop="comMedicalRate" />



</el-table-column>
<el-table-column label="失业保险缴纳比例" align="center" >

  <el-table-column label="个人" align="center" prop="perUnemploymentRate" />
      <el-table-column label="企业" align="center" prop="comUnemploymentRate" />



</el-table-column>



  <el-table-column label="企业生育保险缴费比例" align="center" prop="comMaternityRate" />



<!-- 
      <el-table-column label="职工上年度平均月工资" align="center" prop="averageSalary" />
      <el-table-column label="职工上年度最低月工资" align="center" prop="lowerSalary" /> -->
    
     
 
     
    
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hrmanagement:city:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hrmanagement:city:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-drawer
  :title="title"
  :visible.sync="open"
  direction="rtl"
  size="40%"
  >
  <div style="padding-right: 30px;">
     <!-- 添加或修改参保城市对话框 -->
     <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="城市" style="width:380px" prop="name" label-width="150px">
          <el-input
            placeholder="请输入城市名称"
            v-model.trim="form.name"
          />
        </el-form-item>
        <el-form-item label="职工上年度月工资" style="margin-bottom: 4px;">
          <el-form-item label="最低" label-width="80px" style="display:inline-block" prop="lowerSalary">
            <el-input-number
              placeholder="请输入最低月工资"
              v-model="form.lowerSalary"
              :controls="false"
              :precision="3"
            />
          </el-form-item>
          <el-form-item label="平均" label-width="80px" style="display:inline-block" prop="averageSalary">
            <el-input-number
              placeholder="请输入平均月工资"
              v-model="form.averageSalary"
              :controls="false"
              :precision="3"
            />
          </el-form-item>
        </el-form-item>
        <el-form-item label="社保缴纳基数" style="margin-bottom: 4px">
          <el-form-item label="下限" label-width="80px" style="display:inline-block" prop="socLowerLimit">
            <el-input-number
              v-model="form.socLowerLimit"
              :controls="false"
              :precision="3"
              :disabled="true"
            />
          </el-form-item>
          <el-form-item label="上限" label-width="80px" style="display:inline-block" prop="socUpperLimit">
            <el-input-number
              v-model="form.socUpperLimit"
              :controls="false"
              :precision="3"
              :disabled="true"
            />
          </el-form-item>
        </el-form-item>
        <el-form-item label="公积金缴纳基数" style="margin-bottom: 4px">
          <el-form-item label="下限" label-width="80px" style="display:inline-block" prop="houLowerLimit">
            <el-input-number
              v-model="form.houLowerLimit"
              :controls="false"
              :precision="3"
              :disabled="true"
            />
          </el-form-item>
          <el-form-item label="上限" label-width="80px" style="display:inline-block" prop="houUpperLimit">
            <el-input-number
              v-model="form.houUpperLimit"
              :controls="false"
              :precision="3"
              :disabled="true"
            />
          </el-form-item>
        </el-form-item>
        <el-form-item label="养老保险缴费比例" style="margin-bottom: 4px">
          <el-form-item label="企业" label-width="80px" style="display:inline-block" prop="comPensionRate">
            <el-input-number
              placeholder="请输入"
              v-model="form.comPensionRate"
              :precision="3"
              :step="0.001"
            />
          </el-form-item>
          <el-form-item label="个人" label-width="80px" style="display:inline-block" prop="perPensionRate">
            <el-input-number
              placeholder="请输入"
              v-model="form.perPensionRate"
              :precision="3"
              :step="0.001"
            />
          </el-form-item>
        </el-form-item>
        <el-form-item label="医疗保险缴费比例" style="margin-bottom: 4px">
          <el-form-item label="企业" label-width="80px" style="display:inline-block" prop="comMedicalRate">
            <el-input-number
              placeholder="请输入"
              v-model="form.comMedicalRate"
              :precision="3"
              :step="0.001"
            />
          </el-form-item>
          <el-form-item label="个人" label-width="80px" style="display:inline-block" prop="perMedicalRate">
            <el-input-number
              placeholder="请输入"
              v-model="form.perMedicalRate"
              :precision="3"
              :step="0.001"
            />
          </el-form-item>

        </el-form-item>
        <el-form-item label="失业保险缴费比例" style="margin-bottom: 4px">
          <el-form-item label="企业" label-width="80px" style="display:inline-block" prop="comUnemploymentRate">
            <el-input-number
              placeholder="请输入"
              v-model="form.comUnemploymentRate"
              :precision="3"
              :step="0.001"
            />
          </el-form-item>
          <el-form-item label="个人" label-width="80px" style="display:inline-block" prop="perUnemploymentRate">
            <el-input-number
              placeholder="请输入"
              v-model="form.perUnemploymentRate"
              :precision="3"
              :step="0.001"
            />
          </el-form-item>

        </el-form-item>
        <el-form-item label="生育保险缴费比例" style="margin-bottom: 4px">
          <el-form-item label="企业" label-width="80px" prop="comMaternityRate">
            <el-input-number
              placeholder="请输入"
              v-model="form.comMaternityRate"
              :precision="3"
              :step="0.001"
            />
          </el-form-item>
        </el-form-item>
        <el-form-item label="备注" style="width:480px" prop="remark">
          <el-input
            type="textarea"
            placeholder="请输入"
            v-model.trim="form.remark"
            :autosize="{ minRows: 2, maxRows: 4}"
            maxlength="100"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      <div slot="footer" style="text-align: right;margin-right: 20px;">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
  </div>
   </el-drawer>
  
  </div>
</template>

<script>
import { listCity, getCity, delCity, addCity, updateCity } from "@/api/hrmanagement/city";

export default {
  name: "City",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参保城市表格数据
      cityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      // rules: {
        //   name: [
        //     { required: true, message: '请输入城市名称', trigger: 'blur' }
        //   ],
        //   lowerSalary: [
        //     { required: true, message: '请输入职工上年度平均月工资', trigger: 'blur' },
        //     { type: 'number', min: 500, message: '不低于500元', trigger: 'blur' }
        //   ],
        //   averageSalary: [
        //     { required: true, message: '请输入职工上年度最低月工资', trigger: 'blur' },
        //     { validator: checkAverageSalary, trigger: 'blur' }
        //   ],
        //   perPensionRate: [
        //     { required: true, message: '请输入养老保险个人缴纳比例', trigger: 'blur' },
        //     { type: 'number', min: 0, max: 1, message: '缴纳比例：0 ~ 1', trigger: 'blur' }
        //   ],
        //   comPensionRate: [
        //     { required: true, message: '请输入养老保险企业缴纳比例', trigger: 'blur' },
        //     { type: 'number', min: 0, max: 1, message: '缴纳比例：0 ~ 1', trigger: 'blur' }
        //   ],
        //   perMedicalRate: [
        //     { required: true, message: '请输入医疗保险个人缴纳比例', trigger: 'blur' },
        //     { type: 'number', min: 0, max: 1, message: '缴纳比例：0 ~ 1', trigger: 'blur' }
        //   ],
        //   comMedicalRate: [
        //     { required: true, message: '请输入医疗保险企业缴纳比例', trigger: 'blur' },
        //     { type: 'number', min: 0, max: 1, message: '缴纳比例：0 ~ 1', trigger: 'blur' }
        //   ],
        //   perUnemploymentRate: [
        //     { required: true, message: '请输入失业保险个人缴纳比例', trigger: 'blur' },
        //     { type: 'number', min: 0, max: 1, message: '缴纳比例：0 ~ 1', trigger: 'blur' }
        //   ],
        //   comUnemploymentRate: [
        //     { required: true, message: '请输入失业保险企业缴纳比例', trigger: 'blur' },
        //     { type: 'number', min: 0, max: 1, message: '缴纳比例：0 ~ 1', trigger: 'blur' }
        //   ],
        //   comMaternityRate: [
        //     { required: true, message: '请输入生育保险企业缴纳比例', trigger: 'blur' },
        //     { type: 'number', min: 0, max: 1, message: '缴纳比例：0 ~ 1', trigger: 'blur' }
        //   ]
        // }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询参保城市列表 */
    getList() {
      this.loading = true;
      listCity(this.queryParams).then(response => {
        this.cityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        averageSalary: null,
        lowerSalary: null,
        socUpperLimit: null,
        socLowerLimit: null,
        houUpperLimit: null,
        houLowerLimit: null,
        perPensionRate: null,
        comPensionRate: null,
        perMedicalRate: null,
        comMedicalRate: null,
        perUnemploymentRate: null,
        comUnemploymentRate: null,
        comMaternityRate: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加参保城市";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCity(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改参保城市";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCity(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCity(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除参保城市编号为"' + ids + '"的数据项？').then(function() {
        return delCity(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hrmanagement/city/export', {
        ...this.queryParams
      }, `city_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>

</style>